//  
//  ManagedWindow.cs
//  
//  Author:
//       Tsukanov Nikita <keks9n@gmail.com>
// 
//  Copyright (c) 2011 Tsukanov Nikita
// 
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
// 
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.



using System;
namespace SkypeTab
{
	public class ManagedWindow
	{
		IntPtr m_Window;
		
	
		Gdk.Window m_Wrapper;
		[System.Runtime.InteropServices.DllImport("libgtk-x11-2.0.so.0")]
		public static extern IntPtr gdk_window_foreign_new (IntPtr win);
		[System.Runtime.InteropServices.DllImport("libgtk-x11-2.0.so.0")]
		public static extern IntPtr gdk_x11_drawable_get_xid (IntPtr win);
		
	
		public Gdk.Window Wrapper
		{
			get
			{
				return m_Wrapper;
			}
		}
		
		public ManagedWindow (IntPtr Handle)
		{
			m_Window = Handle;
			
			m_Wrapper=new Gdk.Window(gdk_window_foreign_new(Handle));
			

			
		}
		
		public ManagedWindow (Gdk.Window window)
		{
			m_Window=gdk_x11_drawable_get_xid(window.Handle);
			m_Wrapper=window;
		}
		
		public IntPtr Handle
		{
			get
			{
				return m_Window;
			}
		}
		
		
		public bool Urgent
		{
			get
			{
				return X11.X.GetUrgencyHint (m_Window);
			}
		}
		public string Name
		{
			get
			{
				return X11.X.GetWindowName(m_Window);
			}
		}
		public string Role
		{
			get
			{
				return X11.X.GetWindowRole(m_Window);
			}
		}
		
		public void Reparent(Gdk.Window new_parent)
		{
			m_Wrapper.Reparent(new_parent,0,0);
		}
		
		public void Raise()
		{
			X11.X.RaiseWindow(m_Window);
		}
		public void Destroy()
		{
			m_Wrapper.Destroy();
		}
		public void SetFocus()
		{
			X11.X.SetInputFocus(m_Window);
		}
		
		public bool Visible
		{
			get
			{
				X11.X.XWindowAttributes attr=new X11.X.XWindowAttributes();
				X11.X.XGetWindowAttributes(X11.X.Display,m_Window,ref attr);
				return (attr.map_state==X11.X.MapState.IsViewable);
			}
		}
		
		public void MoveAndResize (int x, int y, int width, int height)
		{
			X11.X.MoveAndResize ( m_Window, x, y, width, height);
		}
		
		

		
		
	}
	

	
}

